# 存放网关模块打包好的jar文件，用于docker启动应用。

# 移除原有容器
docker stop charge-collector
docker rm charge-collector
docker rmi charge-collector

# 构建镜像：
# 进入到应用目录
# shellcheck disable=SC2164
cd /mnt/build-space/charge-collector

echo "Start building docker image of charge-collector."
docker build -f ./dockerfile -t charge-collector .

# 准备挂载文件
mkdir -p /mnt/data/charge-collector/{conf,logs}
cp -f /mnt/build-space/charge-collector/jar/bootstrap.yml /mnt/data/charge-collector/conf/bootstrap.yml

# 运行容器：
echo "Start running docker container of charge-collector."
docker run -di --name charge-collector \
-p 9999:9999 \
-v /mnt/data/charge-collector/logs:/opt/charge-collector/logs/charge-collector \
-v /mnt/data/charge-collector/conf:/opt/charge-collector/config \
--privileged=true \
--restart always \
charge-collector

echo "The application charge-collector run completed already!"
echo "You can use command 'docker logs -n 50 charge-collector' to check the program's startup logs."